package com.example.qiniutest.aop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.qiniutest.aop.entity.Student;
import com.example.qiniutest.aop.service.StudentService;
import com.example.qiniutest.aop.vo.StudentVo;
import com.example.qiniutest.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: qiniuTest
 * @description:
 * @author: xpp011
 * @create: 2021-10-27 11:10
 **/

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @PostMapping("/insert")
    public R insert(@RequestBody Student student){
        return R.status(studentService.save(student));
    }

    @DeleteMapping("/remove")
//    @Transactional
    public R remove(@RequestParam List<Long> ids){
        return R.data(studentService.removeByIds(ids));
    }

    @GetMapping("/page")
    public R list(Page<Student> page){
        IPage<Student> studentIPage = studentService.getBaseMapper().selectPage(page, null);
        return R.data(studentIPage);
    }
}
